import { mapGetters,mapActions } from "vuex";
import {  } from '@/common/api.js';
const indexMixin = {
	data() {
		return {
			bannerList:[], // banner图片
			hostGoodsList: [],// 热门商品
			goodsList: [], // 商品列表
			selectIndex: 0, //选中的商品分类
			live_room_id: '',
			typeList: [{
				category_name: '全部',
				category_id: 0,
				count : 1,
				page : 1,
				loadingType : 'more',
				list : []
			}],
		}
	},
	mounted() {
		if(this.hasLogin) {
			//设置购物车数量状态
			this.getCount();
		}
		this.getData()
	},
	computed: {
		...mapGetters(["modelType", "pairStatu"])
	},
	onReachBottom() {
		this.getGoodsData()
	},
	methods: {
		...mapActions("user", ["setModelType", "setPairStatu"]),
		async getData() {
			// 获取首页轮播
			
			uni.stopPullDownRefresh();
		},
		getTypeGoodslist(index) {
			this.selectIndex = index
			this.getGoodsData()
		},
		getGoodsData() {
			const { selectIndex, typeList } = this
			const item = typeList[selectIndex]
			//if(item.loadingType === 'loading' || item.loadingType === 'noMore'){
			//	//防止重复加载
			//	return;
			//}
			console.log('1',{ page, category_id })
			const { page, category_id } = typeList[selectIndex]
			item.loadingType = 'loading'
			console.log('2',{ page, category_id })
			getGoodsList({category_id, page }).then(({ data }) => {
				item.page += 1
				item.list.push(...data.data)
				item.count = data.count
				data.count > item.list.length ?  item.loadingType = 'more' : item.loadingType = 'noMore'
				this.goodsList = item.list
			})
		},
		getLiveInfo() {
			getLiveId().then(({data}) => {
				this.live_room_id = data.live_room_id
			})
		},
		fiterActivi(name) {
			let { activityConfig } = this
			return activityConfig.some(item => {
				return item.fun_name === name
			})
			// ['assemble','bargain','seckill','shoppingcoupon','coupon_center']
		},
	}
}
export default indexMixin
